<?php
class SessionModel {
	private $sessionPath = NULL;
	
	private $sessionFile = NULL;
	
	public function __construct() {
		$this->sessionPath = APP_ROOT.DIRECTORY_SEPARATOR."session";
		if (file_exists($this->sessionPath) == false) mkdir($this->sessionPath, 0777);
	}
	
	/**
	 * 建立SESSION目录,用于进登陆管理.
	 * @param string $sessionPath;
	 * @param string $sessionName;
	 * @return true/false
	 */
	public function openSession($sessionPath, $sessionName) {
		return true;
	}
	
	/**
	 * 关闭SESSION
	 */
	public function sessionClose() {
		return true;
	}
	
	public function sessionMkFile($sessionId) {
		$this->sessionFile = $this->sessionPath.DIRECTORY_SEPARATOR.$sessionId;
		if (file_exists($this->sessionFile) == false) touch($this->sessionFile);
	}
	
	/**
	 * 读取SESSION 内容. 
	 */
	public function sessionRead($sessionId) {
		$this->sessionMkFile($sessionId);
		return file_get_contents($this->sessionFile);
	}
	
	/**
	 * 写入SESSION内容. 
	 */
	public function sessionWrite($sessionId, $data) {
		$this->sessionMkFile($sessionId);
		file_put_contents($this->sessionFile, $data);
	}
	
	/**
	 * 销毁SESSION 
	 */
	public function sessionDestroy($sessionId) {
		$this->sessionMkFile($sessionId);
		unlink($this->sessionFile);
	}
	
	/**
	 * 清除超时SESSION 
	 */
	public function sessionGc($maxlifetime) {
		
	}
}